home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / util / suplib.1 < prev    next >
Text File  |  1988-10-22  |  55KB  |  2,276 lines

  1. Path: xanth!nic.MR.NET!hal!cwjcc!tut.cis.ohio-state.edu!bloom-beacon!husc6!bbn!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i005:  suplib - Matt's support library, Part01/02
  5. Message-ID: <9765@swan.ulowell.edu>
  6. Date: 22 Oct 88 03:59:39 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 2265
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: dillon@cory.berkeley.edu (Matt Dillon)
  12. Posting-number: Volume 2, Issue 5
  13. Archive-name: util/suplib.1
  14.  
  15. [You need these library support routines and include files
  16. to compile most of Matt's source code.        ..Bob]
  17.  
  18. # This is a shell archive.  Remove anything before this line
  19. # then unpack it by saving it in a file and typing "sh file"
  20. # (Files unpacked will be owned by you and have default permissions).
  21. # This archive contains the following files:
  22. #    ./suplib/break.c
  23. #    ./suplib/lunlink.c
  24. #    ./suplib/setfiledate.c
  25. #    ./suplib/NEW/compress.c
  26. #    ./suplib/NEW/checkmsg.a68
  27. #    ./suplib/NEW/waitmsg.a68
  28. #    ./suplib/NEW/ioctl.doc
  29. #    ./suplib/NEW/port.c
  30. #    ./suplib/NEW/putsmsg.c
  31. #    ./suplib/NEW/gethead.a68
  32. #    ./suplib/NEW/gettail.a68
  33. #    ./suplib/resource.asm
  34. #    ./suplib/dio.c
  35. #    ./suplib/asyncop.c
  36. #    ./suplib/enviroment.c
  37. #    ./suplib/typedefs.h
  38. #    ./suplib/xmisc.h
  39. #    ./suplib/dio.h
  40. #    ./suplib/conwin.c
  41. #
  42. if `test ! -d ./suplib`
  43. then
  44.   mkdir ./suplib
  45.   echo "mkdir ./suplib"
  46. fi
  47. if `test ! -s ./suplib/break.c`
  48. then
  49. echo "writing ./suplib/break.c"
  50. cat > ./suplib/break.c << '\Rogue\Monster\'
  51.  
  52. extern int Enable_Abort;
  53.  
  54. disablebreak()
  55. {
  56.     Enable_Abort = 0;
  57. }
  58.  
  59. enablebreak()
  60. {
  61.     Enable_Abort = 1;
  62. }
  63.  
  64.  
  65. \Rogue\Monster\
  66. else
  67.   echo "will not over write ./suplib/break.c"
  68. fi
  69. if [ `wc -c ./suplib/break.c | awk '{printf $1}'` -ne 111 ]
  70. then
  71. echo `wc -c ./suplib/break.c | awk '{print "Got " $1 ", Expected " 111}'`
  72. fi
  73. if `test ! -s ./suplib/lunlink.c`
  74. then
  75. echo "writing ./suplib/lunlink.c"
  76. cat > ./suplib/lunlink.c << '\Rogue\Monster\'
  77.  
  78. #include <local/xmisc.h>
  79.  
  80. XLIST *
  81. lunlink(en)
  82. register XLIST *en;
  83. {
  84.     if (en) {
  85.     if (en->next)
  86.         en->next->prev = en->prev;
  87.     *en->prev = en->next;
  88.     en->next = NULL;
  89.     en->prev = NULL;
  90.     }
  91.     return(en);
  92. }
  93.  
  94.  
  95.  
  96. \Rogue\Monster\
  97. else
  98.   echo "will not over write ./suplib/lunlink.c"
  99. fi
  100. if [ `wc -c ./suplib/lunlink.c | awk '{printf $1}'` -ne 216 ]
  101. then
  102. echo `wc -c ./suplib/lunlink.c | awk '{print "Got " $1 ", Expected " 216}'`
  103. fi
  104. if `test ! -s ./suplib/setfiledate.c`
  105. then
  106. echo "writing ./suplib/setfiledate.c"
  107. cat > ./suplib/setfiledate.c << '\Rogue\Monster\'
  108.  
  109. /*
  110.  *  SETFILEDATE.C
  111.  *
  112.  *  BOOL = setfiledate(filename, date)
  113.  */
  114.  
  115. #define BTOC(bptr)    ((long)(bptr) << 2)
  116. #define CTOB(cptr)    ((long)(cptr) >> 2)
  117.  
  118. #ifndef ACTION_SET_DATE
  119. #define ACTION_SET_DATE 34
  120. #endif
  121.  
  122. typedef struct Task          TASK;
  123. typedef struct Process          PROC;
  124. typedef struct StandardPacket STDPKT;
  125. typedef struct MsgPort          MSGPORT;
  126. typedef struct FileLock       LOCK;
  127. typedef struct DateStamp      DATESTAMP;
  128.  
  129. extern TASK *FindTask();
  130. extern void *AllocMem();
  131.  
  132. setfiledate(file, date)
  133. char *file;
  134. DATESTAMP *date;
  135. {
  136.     register STDPKT *packet;
  137.     register char   *buf;
  138.     register PROC   *proc;
  139.     long    result;
  140.     long    lock;
  141.  
  142.     {
  143.     register long flock = Lock(file, SHARED_LOCK);
  144.     register short i;
  145.     register char *ptr = file;
  146.  
  147.     if (flock == NULL)
  148.         return(NULL);
  149.     lock = ParentDir(flock);
  150.     UnLock(flock);
  151.     if (!lock)
  152.         return(NULL);
  153.     for (i = strlen(ptr) - 1; i >= 0; --i) {
  154.         if (ptr[i] == '/' || ptr[i] == ':')
  155.         break;
  156.     }
  157.     file += i + 1;
  158.     }
  159.     proc   = (PROC *)FindTask(NULL);
  160.     packet = (STDPKT   *)AllocMem(sizeof(STDPKT), MEMF_CLEAR|MEMF_PUBLIC);
  161.     buf = AllocMem(strlen(file)+2, MEMF_PUBLIC);
  162.     strcpy(buf+1,file);
  163.     buf[0] = strlen(file);
  164.  
  165.     packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  166.     packet->sp_Pkt.dp_Link = &packet->sp_Msg;
  167.     packet->sp_Pkt.dp_Port = &proc->pr_MsgPort;
  168.     packet->sp_Pkt.dp_Type = ACTION_SET_DATE;
  169.     packet->sp_Pkt.dp_Arg1 = NULL;
  170.     packet->sp_Pkt.dp_Arg2 = (long)lock;        /*  lock on parent dir of file  */
  171.     packet->sp_Pkt.dp_Arg3 = (long)CTOB(buf);   /*  BPTR to BSTR of file name   */
  172.     packet->sp_Pkt.dp_Arg4 = (long)date;        /*  APTR to datestamp structure */
  173.     PutMsg(((LOCK *)BTOC(lock))->fl_Task, packet);
  174.     WaitPort(&proc->pr_MsgPort);
  175.     GetMsg(&proc->pr_MsgPort);
  176.     result = packet->sp_Pkt.dp_Res1;
  177.     FreeMem(packet, sizeof(STDPKT));
  178.     FreeMem(buf, strlen(file)+2);
  179.     UnLock(lock);
  180.     return(result);
  181. }
  182.  
  183. \Rogue\Monster\
  184. else
  185.   echo "will not over write ./suplib/setfiledate.c"
  186. fi
  187. if [ `wc -c ./suplib/setfiledate.c | awk '{printf $1}'` -ne 1951 ]
  188. then
  189. echo `wc -c ./suplib/setfiledate.c | awk '{print "Got " $1 ", Expected " 1951}'`
  190. fi
  191. if `test ! -d ./suplib/NEW`
  192. then
  193.   mkdir ./suplib/NEW
  194.   echo "mkdir ./suplib/NEW"
  195. fi
  196. if `test ! -s ./suplib/NEW/compress.c`
  197. then
  198. echo "writing ./suplib/NEW/compress.c"
  199. cat > ./suplib/NEW/compress.c << '\Rogue\Monster\'
  200.  
  201. /*
  202.  *  Independant compress/uncompress module.  User must supply the
  203.  *  following routines:
  204.  *
  205.  *  c      = cgetchar()          (returns EOF on end/error)
  206.  *  (void)  cputchar(c)
  207.  *  len   = cread(buf, len)     (returns EOF on end/error)
  208.  *  (void)  cwrite(buf, len)
  209.  *
  210.  *  Calls:    Compress(filesize)      (filesize used only to optimize hash table)
  211.  *        UnCompress()
  212.  */
  213.  
  214. #include <stdio.h>
  215.  
  216. #ifndef min
  217. #define min(a,b)        ((a>b) ? b : a)
  218. #endif
  219.  
  220. #define BITS        13
  221.  
  222. #if BITS == 16
  223. #define HSIZE  69001           /* 95% occupancy */
  224. #endif
  225. #if BITS == 15
  226. #define HSIZE  35023           /* 94% occupancy */
  227. #endif
  228. #if BITS == 14
  229. #define HSIZE  18013           /* 91% occupancy */
  230. #endif
  231. #if BITS == 13
  232. #define HSIZE  9001           /* 91% occupancy */
  233. #endif
  234. #if BITS <= 12
  235. #define HSIZE  5003           /* 80% occupancy */
  236. #endif
  237.  
  238. typedef long        code_int;
  239. typedef long        count_int;
  240. typedef unsigned char    char_type;
  241. typedef unsigned short    uword;
  242.  
  243. #define MAXCODE(n_bits)  ((1 << (n_bits)) - 1)
  244. #define INIT_BITS 9            /* initial number of bits/code */
  245.  
  246. static int n_bits;                   /* number of bits/code           */
  247. static int maxbits;                   /* user settable max # bits/code    */
  248. static code_int maxcode;               /* maximum code, given n_bits       */
  249. static code_int maxmaxcode;               /* should NEVER generate this code  */
  250. static long  CLen;
  251.  
  252. static count_int   htab[HSIZE];
  253. static uword       codetab[HSIZE];
  254.  
  255. #define htabof(i)       htab[i]
  256. #define codetabof(i)    codetab[i]
  257.  
  258. static code_int hsize = HSIZE;               /* for dynamic table sizing */
  259.  
  260. #define tab_prefixof(i)     codetabof(i)
  261. #define tab_suffixof(i)     ((char_type *)(htab))[i]
  262. #define de_stack        ((char_type *)&tab_suffixof(1<<BITS))
  263.  
  264. static code_int free_ent;               /* first unused entry */
  265.  
  266. code_int getcode();
  267.  
  268. #define CHECK_GAP 10000 /* ratio check interval */
  269.  
  270. static int     block_compress = 1;
  271. static int     clear_flg;
  272. static long    ratio;
  273. static count_int checkpoint;
  274.  
  275. #define FIRST    257    /* first free entry */
  276. #define CLEAR    256    /* table clear output code */
  277.  
  278. static int offset;
  279. long int in_count = 1;            /* length of input */
  280.  
  281. void
  282. Compress(fsize)
  283. {
  284.     long fcode;
  285.     code_int i = 0;
  286.     int c;
  287.     code_int ent;
  288.     int disp;
  289.     code_int hsize_reg;
  290.     int hshift;
  291.  
  292.     bzero(htab, sizeof(htab));
  293.     bzero(codetab, sizeof(codetab));
  294.     CLen = 0;
  295.  
  296.     hsize = HSIZE;
  297.     if ( fsize < (1 << 12) )
  298.     hsize = min ( 5003, HSIZE );
  299.     else if ( fsize < (1 << 13) )
  300.     hsize = min ( 9001, HSIZE );
  301.     else if ( fsize < (1 << 14) )
  302.     hsize = min ( 18013, HSIZE );
  303.     else if ( fsize < (1 << 15) )
  304.     hsize = min ( 35023, HSIZE );
  305.     else if ( fsize < 47000 )
  306.     hsize = min ( 50021, HSIZE );
  307.  
  308.     offset = clear_flg = ratio = 0;
  309.     in_count = 1;
  310.     checkpoint = CHECK_GAP;
  311.     n_bits  = INIT_BITS;        /* number of bits/code            */
  312.     maxbits = BITS;            /* user settable max # bits/code    */
  313.     maxcode = MAXCODE(INIT_BITS);       /* maximum code, given n_bits       */
  314.     maxmaxcode = 1 << BITS;        /* should NEVER generate this code  */
  315.     free_ent = ((block_compress) ? FIRST : 256 );
  316.  
  317.     ent = ngetchar();
  318.  
  319.     hshift = 0;
  320.     for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
  321.     hshift++;
  322.     hshift = 8 - hshift;        /* set hash code range bound */
  323.  
  324.     hsize_reg = hsize;
  325.     cl_hash((count_int)hsize_reg);      /* clear hash table */
  326.  
  327.     while ((c = ngetchar()) != EOF) {
  328.     in_count++;
  329.     fcode = (long) (((long) c << maxbits) + ent);
  330.     i = ((c << hshift) ^ ent);      /* xor hashing */
  331.  
  332.     if (htabof (i) == fcode) {
  333.         ent = codetabof(i);
  334.         continue;
  335.     } else if ((long)htabof (i) < 0)    /* empty slot */
  336.         goto nomatch;
  337.     disp = hsize_reg - i;        /* secondary hash (after G. Knott) */
  338.     if (i == 0)
  339.         disp = 1;
  340. probe:
  341.     if ((i -= disp) < 0)
  342.         i += hsize_reg;
  343.  
  344.     if (htabof (i) == fcode) {
  345.         ent = codetabof(i);
  346.         continue;
  347.     }
  348.     if ((long)htabof (i) > 0)
  349.         goto probe;
  350. nomatch:
  351.     output ((code_int) ent);
  352.     ent = c;
  353.     if (free_ent < maxmaxcode) {
  354.         codetabof(i) = free_ent++; /* code -> hashtable */
  355.         htabof(i) = fcode;
  356.     }
  357.     else if ((count_int)in_count >= checkpoint && block_compress)
  358.         cl_block ();
  359.     }
  360.  
  361.     /*
  362.      * Put out the final code.
  363.      */
  364.  
  365.     output((code_int)ent);
  366.     output((code_int)-1);
  367. }
  368.  
  369. static char buf[BITS];
  370.  
  371. char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
  372. char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
  373.  
  374. output( code )
  375. code_int  code;
  376. {
  377.     register int r_off = offset, bits= n_bits;
  378.     register char * bp = buf;
  379.  
  380.     if ( code >= 0 ) {
  381.     /*
  382.      * Get to the first byte.
  383.      */
  384.     bp += (r_off >> 3);
  385.     r_off &= 7;
  386.     /*
  387.      * Since code is always >= 8 bits, only need to mask the first
  388.      * hunk on the left.
  389.      */
  390.     *bp = (*bp & rmask[r_off]) | (code << r_off) & lmask[r_off];
  391.     bp++;
  392.     bits -= (8 - r_off);
  393.     code >>= 8 - r_off;
  394.     /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
  395.     if ( bits >= 8 ) {
  396.         *bp++ = code;
  397.         code >>= 8;
  398.         bits -= 8;
  399.     }
  400.     /* Last bits. */
  401.     if(bits)
  402.         *bp = code;
  403.  
  404.     offset += n_bits;
  405.     if (offset == (n_bits << 3)) {
  406.         bp = buf;
  407.         bits = n_bits;
  408.         cwrite(bp, bits);
  409.         CLen += bits;
  410.         bp += bits;
  411.         bits = 0;
  412.         offset = 0;
  413.     }
  414.  
  415.     /*
  416.      * If the next entry is going to be too big for the code size,
  417.      * then increase it, if possible.
  418.      */
  419.  
  420.     if (free_ent > maxcode || (clear_flg > 0)) {
  421.         /*
  422.          * Write the whole buffer, because the input side won't
  423.          * discover the size increase until after it has read it.
  424.          */
  425.         if (offset > 0)
  426.         cwrite(buf, n_bits);
  427.         offset = 0;
  428.  
  429.         if (clear_flg) {
  430.         n_bits = INIT_BITS;
  431.         maxcode = MAXCODE(INIT_BITS);
  432.         clear_flg = 0;
  433.         } else {
  434.         n_bits++;
  435.         if (n_bits == maxbits)
  436.             maxcode = maxmaxcode;
  437.         else
  438.             maxcode = MAXCODE(n_bits);
  439.         }
  440.     }
  441.     } else {
  442.     /*
  443.      * At EOF, write the rest of the buffer.
  444.      */
  445.     if (offset > 0)
  446.         cwrite(buf, (offset + 7) / 8);
  447.     offset = 0;
  448.     }
  449. }
  450.  
  451. cl_block()             /* table clear for block compress */
  452. {
  453.     register long int rat;
  454.  
  455.     checkpoint = in_count + CHECK_GAP;
  456.  
  457.     if (in_count > 0x007fffff) { /* shift will overflow */
  458.     rat = CLen >> 8;
  459.     if (rat == 0) {          /* Don't divide by zero */
  460.         rat = 0x7fffffff;
  461.     } else {
  462.         rat = in_count / rat;
  463.     }
  464.     } else {
  465.     rat = (in_count << 8) / CLen;      /* 8 fractional bits */
  466.     }
  467.     if (rat > ratio) {
  468.     ratio = rat;
  469.     } else {
  470.     ratio = 0;
  471.     cl_hash ( (count_int) hsize );
  472.     free_ent = FIRST;
  473.     clear_flg = 1;
  474.     output ( (code_int) CLEAR );
  475.     }
  476. }
  477.  
  478. cl_hash(hsize)          /* reset code table */
  479.     register count_int hsize;
  480. {
  481.     register count_int *htab_p = htab+hsize;
  482.     register long i;
  483.     register long m1 = -1;
  484.  
  485.     i = hsize - 16;
  486.     do {                /* might use Sys V memset(3) here */
  487.         *(htab_p-16) = m1;
  488.         *(htab_p-15) = m1;
  489.         *(htab_p-14) = m1;
  490.         *(htab_p-13) = m1;
  491.         *(htab_p-12) = m1;
  492.         *(htab_p-11) = m1;
  493.         *(htab_p-10) = m1;
  494.         *(htab_p-9) = m1;
  495.         *(htab_p-8) = m1;
  496.         *(htab_p-7) = m1;
  497.         *(htab_p-6) = m1;
  498.         *(htab_p-5) = m1;
  499.         *(htab_p-4) = m1;
  500.         *(htab_p-3) = m1;
  501.         *(htab_p-2) = m1;
  502.         *(htab_p-1) = m1;
  503.         htab_p -= 16;
  504.     } while ((i -= 16) >= 0);
  505.     for ( i += 16; i > 0; i-- )
  506.         *--htab_p = m1;
  507. }
  508.  
  509. void
  510. UnCompress()
  511. {
  512.     register char_type *stackp;
  513.     register int finchar;
  514.     register code_int code, oldcode, incode;
  515.  
  516.     /*
  517.      * As above, initialize the first 256 entries in the table.
  518.      */
  519.  
  520.     bzero(htab, sizeof(htab));
  521.     bzero(codetab, sizeof(codetab));
  522.  
  523.     offset = clear_flg = ratio = 0;
  524.     in_count = 1;
  525.     checkpoint = CHECK_GAP;
  526.     n_bits  = INIT_BITS;        /* number of bits/code            */
  527.     maxbits = BITS;            /* user settable max # bits/code    */
  528.     maxcode = MAXCODE(INIT_BITS);       /* maximum code, given n_bits       */
  529.     maxmaxcode = 1 << BITS;        /* should NEVER generate this code  */
  530.  
  531.     for ( code = 255; code >= 0; code-- ) {
  532.     tab_prefixof(code) = 0;
  533.     tab_suffixof(code) = (char_type)code;
  534.     }
  535.     free_ent = ((block_compress) ? FIRST : 256 );
  536.  
  537.     finchar = oldcode = getcode();
  538.     if (oldcode == -1)          /* EOF already? */
  539.     return;         /* Get out of here */
  540.     cputchar((char)finchar);       /* first code must be 8 bits = char */
  541.     ++CLen;
  542.     stackp = de_stack;
  543.  
  544.     while ((code = getcode()) > -1) {
  545.     if ((code == CLEAR) && block_compress) {
  546.         for (code = 255; code >= 0; code--)
  547.         tab_prefixof(code) = 0;
  548.         clear_flg = 1;
  549.         free_ent = FIRST - 1;
  550.         if ((code = getcode()) == -1)   /* O, untimely death! */
  551.         break;
  552.     }
  553.     incode = code;
  554.     /*
  555.      * Special case for KwKwK string.
  556.      */
  557.     if (code >= free_ent) {
  558.         *stackp++ = finchar;
  559.         code = oldcode;
  560.     }
  561.  
  562.     /*
  563.      * Generate output characters in reverse order
  564.      */
  565.     while ( code >= 256 ) {
  566.         *stackp++ = tab_suffixof(code);
  567.         code = tab_prefixof(code);
  568.     }
  569.     *stackp++ = finchar = tab_suffixof(code);
  570.  
  571.     /*
  572.      * And put them out in forward order
  573.      */
  574.     do {
  575.         cputchar (*--stackp);
  576.         ++CLen;
  577.     }
  578.     while (stackp > de_stack);
  579.  
  580.     /*
  581.      * Generate the new entry.
  582.      */
  583.     if ((code=free_ent) < maxmaxcode) {
  584.         tab_prefixof(code) = (unsigned short)oldcode;
  585.         tab_suffixof(code) = finchar;
  586.         free_ent = code+1;
  587.     }
  588.     /*
  589.      * Remember previous code.
  590.      */
  591.     oldcode = incode;
  592.     }
  593. }
  594.  
  595. code_int
  596. getcode()
  597. {
  598.     /*
  599.      * On the VAX, it is important to have the register declarations
  600.      * in exactly the order given, or the asm will break.
  601.      */
  602.  
  603.     register code_int code;
  604.     static int offset = 0, size = 0;
  605.     static char_type buf[BITS];
  606.     register int r_off, bits;
  607.     register char_type *bp = buf;
  608.  
  609.     if (clear_flg > 0 || offset >= size || free_ent > maxcode) {
  610.     /*
  611.      * If the next entry will be too big for the current code
  612.      * size, then we must increase the size.  This implies reading
  613.      * a new buffer full, too.
  614.      */
  615.     if ( free_ent > maxcode ) {
  616.         n_bits++;
  617.         if ( n_bits == maxbits )
  618.         maxcode = maxmaxcode;    /* won't get any bigger now */
  619.         else
  620.         maxcode = MAXCODE(n_bits);
  621.     }
  622.     if ( clear_flg > 0) {
  623.         maxcode = MAXCODE (n_bits = INIT_BITS);
  624.         clear_flg = 0;
  625.     }
  626.     size = cread(buf, n_bits);
  627.     if (size <= 0)
  628.         return -1;            /* end of file */
  629.     offset = 0;
  630.     size = (size << 3) - (n_bits - 1);
  631.     }
  632.     r_off = offset;
  633.     bits = n_bits;
  634.  
  635.     /*
  636.      * Get to the first byte.
  637.      */
  638.     bp += (r_off >> 3);
  639.     r_off &= 7;
  640.     /* Get first part (low order bits) */
  641.  
  642.     code = (*bp++ >> r_off);
  643.  
  644.     bits -= (8 - r_off);
  645.     r_off = 8 - r_off;        /* now, offset into code word */
  646.     /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
  647.     if ( bits >= 8 ) {
  648.         code |= *bp++ << r_off;
  649.         r_off += 8;
  650.         bits -= 8;
  651.     }
  652.     /* high order bits. */
  653.     code |= (*bp & rmask[bits]) << r_off;
  654.  
  655.     offset += n_bits;
  656.  
  657.     return code;
  658. }
  659.  
  660.  
  661. #asm
  662.         ;    static (to this module only) bzero... simple and
  663.         ;    stupid.  Non critical.
  664.  
  665. _bzero:     move.l  4(sp),A0
  666.         move.l  8(sp),D0
  667.         beq     .bz2
  668. .bz1        clr.b   D1
  669.         move.b  D1,(A0)+
  670.         subq.l  #1,D0
  671.         bne     .bz1
  672. .bz2        rts
  673. #endasm
  674.  
  675. \Rogue\Monster\
  676. else
  677.   echo "will not over write ./suplib/NEW/compress.c"
  678. fi
  679. if [ `wc -c ./suplib/NEW/compress.c | awk '{printf $1}'` -ne 10805 ]
  680. then
  681. echo `wc -c ./suplib/NEW/compress.c | awk '{print "Got " $1 ", Expected " 10805}'`
  682. fi
  683. if `test ! -s ./suplib/NEW/checkmsg.a68`
  684. then
  685. echo "writing ./suplib/NEW/checkmsg.a68"
  686. cat > ./suplib/NEW/checkmsg.a68 << '\Rogue\Monster\'
  687.  
  688.         public    _CheckMsg
  689.  
  690. NT_MESSAGE    equ    5
  691. NT_FREEMSG    equ    6
  692. NT_REPLYMSG    equ    7
  693.  
  694. CheckMsg:
  695.         move.l    4(sp),A0            ; message
  696.         clr.l    D0
  697.         cmp.b    #NT_MESSAGE,8(A0)   ; type
  698.         beq    .1
  699.         move.l    A0,D0
  700. .1        rts
  701.  
  702. \Rogue\Monster\
  703. else
  704.   echo "will not over write ./suplib/NEW/checkmsg.a68"
  705. fi
  706. if [ `wc -c ./suplib/NEW/checkmsg.a68 | awk '{printf $1}'` -ne 202 ]
  707. then
  708. echo `wc -c ./suplib/NEW/checkmsg.a68 | awk '{print "Got " $1 ", Expected " 202}'`
  709. fi
  710. if `test ! -s ./suplib/NEW/waitmsg.a68`
  711. then
  712. echo "writing ./suplib/NEW/waitmsg.a68"
  713. cat > ./suplib/NEW/waitmsg.a68 << '\Rogue\Monster\'
  714.  
  715.         public    _WaitMsg
  716.         public    _LVOWait
  717.         public    _SysBase
  718.  
  719. NT_MESSAGE    equ    5
  720. NT_FREEMSG    equ    6
  721. NT_REPLYMSG    equ    7
  722.  
  723. _WaitMsg:
  724.         movem.l A2/A6,-(sp)
  725.         move.l    12(sp),A2           ; A2 = message
  726.         move.l    _SysBase,A6
  727. .1        cmp.b    #NT_REPLYMSG,8(A2)  ; has it been replied?
  728.         beq    .10
  729. .2        cmp.b    #NT_FREEMSG,8(A2)   ; has it been freed?
  730.         beq    .15
  731.         move.l    14(A2),A1           ; reply port
  732.         tst.l    A1
  733.         beq    .1            ; NULL reply port, busy wait.
  734.         move.b    15(A1),D1           ; signal bit #
  735.         moveq.l #1,D0
  736.         asl.l    D1,D0            ; D0 = signal mask
  737.         jsr    _LVOWait(A6)        ; wait for signal
  738.         bra    .1            ; loop again
  739. .10        jsr    _LVODisable(A6)
  740.         move.l    A2,A1
  741.         jsr    _LVORemove(A6)
  742.         jsr    _LVOEnable(A6)
  743. .15        movem.l (sp)+,A2/A6         ; return the message
  744.         move.l    A2,D0
  745.         rts
  746.  
  747. \Rogue\Monster\
  748. else
  749.   echo "will not over write ./suplib/NEW/waitmsg.a68"
  750. fi
  751. if [ `wc -c ./suplib/NEW/waitmsg.a68 | awk '{printf $1}'` -ne 754 ]
  752. then
  753. echo `wc -c ./suplib/NEW/waitmsg.a68 | awk '{print "Got " $1 ", Expected " 754}'`
  754. fi
  755. if `test ! -s ./suplib/NEW/ioctl.doc`
  756. then
  757. echo "writing ./suplib/NEW/ioctl.doc"
  758. cat > ./suplib/NEW/ioctl.doc << '\Rogue\Monster\'
  759.  
  760.                 IOCTL.DOC
  761.  
  762. IO control interface
  763.  
  764.             (main routines)
  765.  
  766.          IoOpen("device")
  767.     result = IoCtl(fd,cmd,arg1,arg2)
  768.     result = IoAbort(fd)
  769.     fd2    = IoDup(fd)
  770.          IoClose(fd)
  771.  
  772.             (useful macros)
  773.  
  774.          IoRead(fd,buf,len)                 normal io
  775.          IoReadA(fd,buf,len)
  776.          IoWrite(fd,buf,len)
  777.          IoWriteA(fd,buf,len)
  778.          IoReadExt(fd,buf,len,offset)       extended io
  779.          IoWriteExt(fd,buf,len,offset)
  780.          IoReadExtA(fd,buf,len,offset)
  781.          IoWriteExtA(fd,buf,len,offset)
  782.  
  783.     cmd:    FEDCBA98  76543210     FEDCBA9876543210
  784.         <GENFLGS> <SPECFLGS> <COMMAND NUMBER>
  785.  
  786.     General Flags:  Device Independant flags
  787.     Specific Flags: Device Dependant flags (reused by devices)
  788.     Command Number: Command # (unique)
  789.  
  790.  
  791.  
  792.         GENERAL CALLS
  793.  
  794.     IOF_ASYNC        asynchronous flag (result will be negative or 0)
  795.  
  796.     IOC_RESET        reset device
  797.     IOC_READ        read or start asynch read
  798.     IOC_WRITE        write or start asynch write
  799.     IOC_UPDATE        update device
  800.     IOC_CLEAR        clear device
  801.     IOC_STOP        stop device
  802.     IOC_START        start device
  803.     IOC_FLUSH        flush device
  804.  
  805.     IOC_FLAGS        IoCtl flags:    IOCF_NBIO        non-blocking IO
  806.                     IOCF_TIMEOUT    if not IOCF_NBIO, block abort timeout
  807.     IOC_TIMEOUT     set automatic timeout period (default 0=disabled)
  808.     IOC_SIGNAL        return associated signal
  809.     IOC_SETSIG        set associated SigNo.
  810.     IOC_CHECK        check pending request (-1=pulled, 0=ready, 1=pending)
  811.     IOC_WAIT        wait for pending request
  812.  
  813.         IOCTL DEVICE
  814.  
  815.     IOC_IOCADDDEVICE
  816.     IOC_IOCREMDEVICE
  817.  
  818.         AUDIO DEVICE
  819.  
  820.     IOC_AUDFLAGS    set/clear ADIOF_* flags
  821.     IOC_AUDFREE     (normal device call)
  822.     IOC_AUDSETPREC
  823.     IOC_AUDFINISH
  824.     IOC_AUDPERVOL
  825.     IOC_AUDLOCK
  826.     IOC_AUDWAITCYC
  827.  
  828.         CLIPBOARD DEVICE
  829.  
  830.     IOC_CLPOST
  831.     IOC_CLCREADID
  832.     IOC_CLCWRITEID
  833.  
  834.         CONSOLE DEVICE
  835.  
  836.     IOC_CONASKKEYMAP
  837.     IOC_CONSETKEYMAP
  838.     IOC_CONASKDEFKM
  839.     IOC_CONSETDEFKM
  840.  
  841.         GAMEPORT DEVICE
  842.  
  843.     IOC_GPFLAGS
  844.     IOC_GPREADEVENT
  845.     IOC_GPASKCTYPE
  846.     IOC_GPSETCTYPE
  847.     IOC_GPASKTRIGGER
  848.     IOC_GPSETTRIGGER
  849.  
  850.         INPUT DEVICE
  851.  
  852.     IOC_IDADDHANDLER
  853.     IOC_IDREMHANDLER
  854.     IOC_IDWRITEEVENT
  855.     IOC_IDSETTHRESH
  856.     IOC_IDSETPERIOD
  857.     IOC_IDSETMPORT
  858.     IOC_IDSETMTYPE
  859.     IOC_IDSETMTRIG
  860.  
  861.         KEYBOARD DEVICE
  862.  
  863.     IOC_KBREADEVENT
  864.     IOC_KBREADMATRIX
  865.     IOC_KBADDRESHANDLER
  866.     IOC_KBREMRESHANDLER
  867.     IOC_KBRESHANDLERDONE
  868.  
  869.         NARRATOR DEVICE
  870.  
  871.         PARALLEL DEVICE
  872.  
  873.     IOC_PARFLAGS
  874.     IOC_PARQUERY
  875.     IOC_PARPARAMS
  876.  
  877.         PRINTER DEVICE
  878.  
  879.     IOC_PRTRAWWRITE
  880.     IOC_PRTCOMMAND
  881.     IOC_PRTDUMPRPORT
  882.  
  883.         SERIAL DEVICE
  884.  
  885.     IOC_SERFLAGS
  886.     IOC_SERSEXFLAGS
  887.     IOC_SERQUERY
  888.     IOC_SERBREAK
  889.     IOC_SERPARAMS
  890.  
  891.         TIMER DEVICE
  892.  
  893.     IOC_TRSETUNIT
  894.     IOC_TRADDREQUEST
  895.     IOC_TRGETSYSTIME
  896.     IOC_TRSETSYSTIME
  897.  
  898.         TRACKDISK DEVICE
  899.  
  900.     IOF_TDEXTCOM
  901.  
  902.     IOC_TDSETOFFSET
  903.     IOC_TDFLAGS
  904.  
  905.     IOC_TDMOTOR
  906.     IOC_TDSEEK
  907.     IOC_TDFORMAT
  908.     IOC_TDREMOVE
  909.     IOC_TDCHANGENUM
  910.     IOC_TDCHANGESTATE
  911.     IOC_TDPROTSTATUS
  912.     IOC_TDRAWREAD
  913.     IOC_TDRAWWRITE
  914.     IOC_TDGETDRIVETYPE
  915.     IOC_TDGETNUMTRACKS
  916.     IOC_TDADDCHANGEINT
  917.     IOC_TDREMCHANGEINT
  918.  
  919.  
  920.  
  921. \Rogue\Monster\
  922. else
  923.   echo "will not over write ./suplib/NEW/ioctl.doc"
  924. fi
  925. if [ `wc -c ./suplib/NEW/ioctl.doc | awk '{printf $1}'` -ne 3089 ]
  926. then
  927. echo `wc -c ./suplib/NEW/ioctl.doc | awk '{print "Got " $1 ", Expected " 3089}'`
  928. fi
  929. if `test ! -s ./suplib/NEW/port.c`
  930. then
  931. echo "writing ./suplib/NEW/port.c"
  932. cat > ./suplib/NEW/port.c << '\Rogue\Monster\'
  933.  
  934. /*
  935.  *  CreateUniquePort(name, pri)
  936.  *  DeleteUniquePort(port)
  937.  */
  938.  
  939. #include <exec/types.h>
  940. #include <typdefs.h>
  941.  
  942. typedef struct MsgPort PORT;
  943.  
  944. PORT *
  945. CreateUniquePort(name, priority)
  946. char *name;
  947. {
  948.     register int n = 0;
  949.     register char *ptr;
  950.     register PORT *port;
  951.     char buf[64];
  952.  
  953.     Forbid();
  954.     if (ptr = name) {
  955.     strcpy(buf, name);
  956.     while (FindPort(buf))
  957.         sprintf(buf, "%s.%d\n", name, ++n);
  958.     if (ptr = AllocMem(strlen(buf)+1, MEMF_PUBLIC)) {
  959.         strcpy(ptr, buf);
  960.     } else {
  961.         Permit();
  962.         return(NULL);
  963.     }
  964.     }
  965.     if (!(port = CreatePort(ptr, priority)) && ptr)
  966.     FreeMem(ptr, strlen(ptr)+1);
  967.     Permit();
  968.     return(port);
  969. }
  970.  
  971. DeleteUniquePort(port)
  972. register PORT *port;
  973. {
  974.     register char *name;
  975.  
  976.     RemPort(port);
  977.     if (name = port->mp_Node.ln_Name) {
  978.     FreeMem(name, strlen(name)+1);
  979.     port->mp_Node.ln_Name = NULL;
  980.     }
  981.     DeletePort(port);
  982. }
  983.  
  984. \Rogue\Monster\
  985. else
  986.   echo "will not over write ./suplib/NEW/port.c"
  987. fi
  988. if [ `wc -c ./suplib/NEW/port.c | awk '{printf $1}'` -ne 879 ]
  989. then
  990. echo `wc -c ./suplib/NEW/port.c | awk '{print "Got " $1 ", Expected " 879}'`
  991. fi
  992. if `test ! -s ./suplib/NEW/putsmsg.c`
  993. then
  994. echo "writing ./suplib/NEW/putsmsg.c"
  995. cat > ./suplib/NEW/putsmsg.c << '\Rogue\Monster\'
  996.  
  997. #include <exec/types.h>
  998. #include <typedefs.h>
  999.  
  1000. typedef struct Port PORT;
  1001. typedef struct Message MSG;
  1002.  
  1003. PutSyncMsg(port, msg)
  1004. PORT *port;
  1005. MSG *msg;
  1006. {
  1007.  
  1008. }
  1009.  
  1010.  
  1011. PutSyncMsgSimple(port, ptr, cmd)
  1012. PORT *port;
  1013. MSG *msg;
  1014. {
  1015.  
  1016. }
  1017.  
  1018. \Rogue\Monster\
  1019. else
  1020.   echo "will not over write ./suplib/NEW/putsmsg.c"
  1021. fi
  1022. if [ `wc -c ./suplib/NEW/putsmsg.c | awk '{printf $1}'` -ne 215 ]
  1023. then
  1024. echo `wc -c ./suplib/NEW/putsmsg.c | awk '{print "Got " $1 ", Expected " 215}'`
  1025. fi
  1026. if `test ! -s ./suplib/NEW/gethead.a68`
  1027. then
  1028. echo "writing ./suplib/NEW/gethead.a68"
  1029. cat > ./suplib/NEW/gethead.a68 << '\Rogue\Monster\'
  1030.  
  1031. ;   GETHEAD(list)
  1032. ;   NEXTNODE(node)
  1033. ;        4(sp)
  1034.  
  1035.  
  1036.         public  _gethead
  1037.         public  _nextnode
  1038.  
  1039. _nextnode:
  1040. _gethead:
  1041.         move.l  4(sp),A0    ;A0 = list or node
  1042.         move.l  (A0),A1     ;A1 = lh_Head or ln_Succ
  1043.         move.l  A1,D0    ;D0 = result
  1044.         tst.l   (A1)        ;does it point to lh_Tail?
  1045.         bne     .1        ;no
  1046.         clr.l   D0        ;yes
  1047. .1        rts
  1048.  
  1049. \Rogue\Monster\
  1050. else
  1051.   echo "will not over write ./suplib/NEW/gethead.a68"
  1052. fi
  1053. if [ `wc -c ./suplib/NEW/gethead.a68 | awk '{printf $1}'` -ne 352 ]
  1054. then
  1055. echo `wc -c ./suplib/NEW/gethead.a68 | awk '{print "Got " $1 ", Expected " 352}'`
  1056. fi
  1057. if `test ! -s ./suplib/NEW/gettail.a68`
  1058. then
  1059. echo "writing ./suplib/NEW/gettail.a68"
  1060. cat > ./suplib/NEW/gettail.a68 << '\Rogue\Monster\'
  1061.  
  1062. ;   GETTAIL(list)
  1063. ;        4(sp)
  1064.  
  1065.  
  1066.         public  _gettail
  1067.  
  1068. _gettail:
  1069.         move.l  4(sp),A0    ;A0 = list
  1070.         move.l  8(A0),A1    ;A1 = lh_TailPred
  1071.         move.l  A1,D0    ;D0 = result
  1072.         cmp.l   A1,A0    ;is it pointing to lh_Head?
  1073.         bne     .1        ;no
  1074.         clr.l   D0        ;yes
  1075. .1        rts
  1076.  
  1077. \Rogue\Monster\
  1078. else
  1079.   echo "will not over write ./suplib/NEW/gettail.a68"
  1080. fi
  1081. if [ `wc -c ./suplib/NEW/gettail.a68 | awk '{printf $1}'` -ne 279 ]
  1082. then
  1083. echo `wc -c ./suplib/NEW/gettail.a68 | awk '{print "Got " $1 ", Expected " 279}'`
  1084. fi
  1085. if `test ! -s ./suplib/resource.asm`
  1086. then
  1087. echo "writing ./suplib/resource.asm"
  1088. cat > ./suplib/resource.asm << '\Rogue\Monster\'
  1089.  
  1090.  ;
  1091.  ;  EXEC resource support
  1092.  ;                   4(sp)  8(sp)
  1093.  ;    AutoAllocMiscResource(resno, value)
  1094.  ;        resno:  MR_SERIALPORT, SERIALBITS, PARALLELPORT, PARALLELBITS
  1095.  ;        value:  -1 to allocate, 0 to check
  1096.  ;
  1097.  ;        returns 0 on success
  1098.  ;
  1099.  ;    AutoFreeMiscResource(resno)
  1100.  ;                  4(sp)
  1101.  ;        Free a misc resource you allocated
  1102.  ;
  1103.  ;    No need to open the misc.resource
  1104.  
  1105.         public  _AutoAllocMiscResource
  1106.         public  _AutoFreeMiscResource
  1107.         public  _LVOOpenResource
  1108.  
  1109.         FAR     DATA
  1110.  
  1111. _AutoAllocMiscResource:
  1112.         move.l  A6,-(sp)
  1113.         bsr     OpenMiscResource
  1114.         beq     amfail
  1115.         move.l  8(sp),D0
  1116.         move.l  12(sp),A1
  1117.         jsr     -6(A6)
  1118.         bra     amret
  1119. amfail        moveq.l #-1,D0
  1120. amret        move.l  (sp)+,A6
  1121.         rts
  1122.  
  1123. _AutoFreeMiscResource:
  1124.         move.l  A6,-(sp)
  1125.         bsr     OpenMiscResource
  1126.         beq     fmret
  1127.         move.l  8(sp),D0
  1128.         jsr     -12(A6)
  1129. fmret        move.l  (sp)+,A6
  1130.         rts
  1131.  
  1132. OpenMiscResource:
  1133.         move.l  4,A6
  1134.         lea.l   MiscName,A1
  1135.         jsr     _LVOOpenResource(A6)
  1136.         move.l  D0,A6
  1137.         tst.l   D0
  1138.         rts
  1139.  
  1140. MiscName:   dc.b    "misc.resource",0
  1141.  
  1142.  
  1143.  
  1144. \Rogue\Monster\
  1145. else
  1146.   echo "will not over write ./suplib/resource.asm"
  1147. fi
  1148. if [ `wc -c ./suplib/resource.asm | awk '{printf $1}'` -ne 1089 ]
  1149. then
  1150. echo `wc -c ./suplib/resource.asm | awk '{print "Got " $1 ", Expected " 1089}'`
  1151. fi
  1152. if `test ! -s ./suplib/dio.c`
  1153. then
  1154. echo "writing ./suplib/dio.c"
  1155. cat > ./suplib/dio.c << '\Rogue\Monster\'
  1156.  
  1157. /*
  1158.  *  DIO.C
  1159.  *
  1160.  *  (C)Copyright 1987 by Matthew Dillon, All rights reserved
  1161.  *  Freely distributable.  Donations Welcome.  This is NOT shareware,
  1162.  *  This is NOT public domain.
  1163.  *
  1164.  *    Matthew Dillon
  1165.  *    891 Regal Rd.
  1166.  *    Berkeley, Ca. 94708
  1167.  *
  1168.  *  EXEC device driver IO support routines... makes everything easy.
  1169.  *
  1170.  *  dfd = dio_open(name, unit, flags, req/NULL)
  1171.  *
  1172.  *    open an IO device.  Note: in some cases you might have to provide
  1173.  *    a request structure with some fields initialized (example, the
  1174.  *    console device requires certain fields to be initialized).  For
  1175.  *    instance, if openning the SERIAL.DEVICE, you would want to give
  1176.  *    an IOExtSer structure which is completely blank execept for the
  1177.  *    io_SerFlags field.
  1178.  *
  1179.  *    The request structure's message and reply ports need not be
  1180.  *    initialized.  The request structure is no longer needed after
  1181.  *    the dio_open().
  1182.  *
  1183.  *    NULL = error, else descriptor (a pointer) returned.
  1184.  *
  1185.  *
  1186.  *  dio_close(dfd)
  1187.  *
  1188.  *    close an IO device.  Any pending asyncronous requests are
  1189.  *    AbortIO()'d and then Wait'ed on for completion.
  1190.  *
  1191.  *
  1192.  *  dio_closegrp(dfd)
  1193.  *
  1194.  *    close EVERY DIO DESCRIPTOR ASSOCIATED WITH THE dio_open() call
  1195.  *    that was the parent for this descriptor.  That is, you can get
  1196.  *    a descriptor using dio_open(), dio_dup() it a couple of times,
  1197.  *    then use dio_closegrp() on any ONE of the resulting descriptors
  1198.  *    to close ALL of them.
  1199.  *
  1200.  *
  1201.  *  dio_ddl(dfd,bool)
  1202.  *
  1203.  *    Disable BUF and LEN fields in dio_ctl[_to].. dummy parameters
  1204.  *    must still be passed, but they are not loaded into the io_Data
  1205.  *    and io_Length fields of the io request.  This is for devices
  1206.  *    like the AUDIO.DEVICE which has io_Data/io_Length in non-standard
  1207.  *    places.
  1208.  *
  1209.  *  dio_cact(dfd,bool)
  1210.  *
  1211.  *    If an error occurs (io_Error field), the io_Actual field is usually
  1212.  *    not modified by the device driver, and thus contains garbage.  To
  1213.  *    provide a cleaner interface, you can have DIO_CTL() and DIO_CTL_TO()
  1214.  *    calls automatically pre-clear this field so if an io_Error does
  1215.  *    occur, the field is a definate 0 instead of garbage.
  1216.  *
  1217.  *    In most cases you will want to do this.  An exception is the
  1218.  *    TIMER.DEVICE, which uses the io_Actual field for part of the
  1219.  *    timeout structure.
  1220.  *
  1221.  *    This flags the particular dio descriptor to do the pre-clear, and
  1222.  *    any new descriptors obtained by DIO_DUP()ing this one will also
  1223.  *    have the pre-clear flag set.
  1224.  *
  1225.  *
  1226.  *  dio_dup(dfd)
  1227.  *
  1228.  *    Returns a new channel descriptor referencing the same device.
  1229.  *    The new descriptor has it's own signal and IO request structure.
  1230.  *    For instance, if you openned the serial device, you might want
  1231.  *    to dup the descriptor so you can use one channel to pend an
  1232.  *    asyncronous read, and the other channel to write out to the device
  1233.  *    and do other things without disturbing the asyncronous read.
  1234.  *
  1235.  *
  1236.  *  sig = dio_signal(dfd)
  1237.  *
  1238.  *    get the signal number (0..31) used for a DIO descriptor.
  1239.  *    This allows you to Wait() for asyncronous requests.  Note that
  1240.  *    if your Wait() returns, you should double check using dio_isdone()
  1241.  *
  1242.  *      dio_flags(dfd, or, ~and)
  1243.  *
  1244.  *    Modify the io_Flags field in the request, ORing it with the OR
  1245.  *    mask, and ANDing it with ~AND mask.  E.G., the AUDIO.DEVICE requires
  1246.  *    some flags be put in io_Flags.
  1247.  *
  1248.  *  req = dio_ctl_to(dfd, command, buf, len, to)
  1249.  *
  1250.  *    Same as DIO_CTL() below, but (A) is always syncronous, and
  1251.  *    (B) will attempt to AbortIO()+WaitIO() the request if the
  1252.  *    timeout occurs before the IO completes.
  1253.  *
  1254.  *    the 'to' argument is in microseconds.
  1255.  *
  1256.  *    If timeout occurs before request completes, and DIO aborts the
  1257.  *    request, some devices do not have the io_Actual field set
  1258.  *    properly.
  1259.  *
  1260.  *  req = dio_ctl(dfd, command, buf, len)
  1261.  *
  1262.  *    DIO_CTL() is the basis for the entire library.  It works as follows:
  1263.  *
  1264.  *    (1) If the channel isn't clear (there is an asyncronous IO request
  1265.  *        still pending), DIO_CTL() waits for it to complete
  1266.  *
  1267.  *    (2) If the command is 0, simply return a pointer to the io
  1268.  *        request structure.
  1269.  *
  1270.  *    (3) If the DIO_CACT() flag is TRUE, the io_Actual field of the
  1271.  *        request is cleared.
  1272.  *
  1273.  *    (4) Set the io_Data field to 'buf', and io_Length field to 'len'
  1274.  *        If the command is positive, use DoIO().  If the command
  1275.  *        negative, take it's absolute value and then do a SendIO().
  1276.  *        (The command is placed in the io_Command field, of course).
  1277.  *
  1278.  *    (5) return the IO request structure
  1279.  *
  1280.  *
  1281.  *  bool= dio_isdone(dfd)
  1282.  *
  1283.  *    return 1 if current channel is clear (done processing), else 0.
  1284.  *    e.g. if you did, say, an asyncronous read, and dio_isdone() returns
  1285.  *    true, you can now use the data buffer returned and look at the
  1286.  *    io_Actual field.
  1287.  *
  1288.  *    You need not do a dio_wait() after dio_isdone() returns 1.
  1289.  *
  1290.  *
  1291.  *  req = dio_wait(dfd)
  1292.  *
  1293.  *    Wait on the current channel for the request to complete and
  1294.  *    then return the request structure. (nop if channel is clear)
  1295.  *
  1296.  *
  1297.  *  req = dio_abort(dfd)
  1298.  *
  1299.  *    Abort the request on the current channel (nop if channel is
  1300.  *    clear).  Sends an AbortIO() if the channel is active and then
  1301.  *    WaitIO()'s the request.
  1302.  *
  1303.  *
  1304.  *  MACROS: SEE DIO.H
  1305.  *
  1306.  */
  1307.  
  1308. #include <exec/types.h>
  1309. #include <exec/io.h>
  1310. #include <exec/memory.h>
  1311. #include <exec/ports.h>
  1312. #include <devices/timer.h>
  1313. #include <local/xmisc.h>
  1314.  
  1315. #define MPC        (MEMF_CLEAR|MEMF_PUBLIC)
  1316. #define CPORT        ior.ior.io_Message.mn_ReplyPort
  1317. #define MAXREQSIZE  128     /* big enough to hold all Amiga iorequests */
  1318.  
  1319. typedef struct IORequest IOR;
  1320. typedef struct IOStdReq  STD;
  1321. typedef struct MsgPort     PORT;
  1322.  
  1323. typedef struct {
  1324.     STD ior;
  1325.     char filler[MAXREQSIZE-sizeof(STD)];
  1326. } MAXIOR;
  1327.  
  1328. typedef struct {
  1329.     struct _CHAN *list;
  1330.     short refs;
  1331. } DIO;
  1332.  
  1333. typedef struct _CHAN {
  1334.     MAXIOR  ior;
  1335.     DIO     *base;
  1336.     XLIST   link;    /* doubly linked list */
  1337.     STD     timer;
  1338.     char    notclear;
  1339.     char    cact;    /* automatic io_Actual field clear  */
  1340.     char    ddl;
  1341.     UBYTE   flagmask;
  1342. } CHAN;
  1343.  
  1344. extern CHAN *dio_ctl(), *dio_ctl_to(), *dio_wait(), *dio_abort();
  1345. extern PORT *CreatePort();
  1346. extern char *AllocMem();
  1347.  
  1348. CHAN *
  1349. dio_open(name, unit, flags, req)
  1350. char *name;
  1351. MAXIOR *req;     /* not really this big  */
  1352. {
  1353.     register CHAN *chan;
  1354.     register DIO *dio;
  1355.     register PORT *port;
  1356.     int ret;
  1357.  
  1358.     dio = (DIO *)AllocMem(sizeof(DIO), MPC);    if (!dio)   goto fail3;
  1359.     chan= (CHAN *)AllocMem(sizeof(CHAN), MPC);  if (!chan)   goto fail2;
  1360.     if (req)
  1361.     chan->ior = *req;
  1362.     chan->CPORT = CreatePort(NULL,0);           if (!chan->CPORT) goto fail1;
  1363.     chan->ior.ior.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  1364.     chan->base = dio;
  1365.     chan->flagmask = 0xF0;
  1366.     dio->refs = 1;
  1367.     if (OpenDevice(name, unit, &chan->ior, flags)) {
  1368.     DeletePort(chan->CPORT);
  1369. fail1:    FreeMem(chan, sizeof(CHAN));
  1370. fail2:    FreeMem(dio, sizeof(DIO));
  1371. fail3:    return(NULL);
  1372.     }
  1373.     llink(&dio->list, &chan->link);
  1374.     chan->ior.ior.io_Flags = 0;
  1375.     return(chan);
  1376. }
  1377.  
  1378. void
  1379. dio_dfm(chan,mask)
  1380. CHAN *chan;
  1381. {
  1382.     chan->flagmask = mask;
  1383. }
  1384.  
  1385. void
  1386. dio_ddl(chan,n)
  1387. CHAN *chan;
  1388. {
  1389.     chan->ddl = n;
  1390. }
  1391.  
  1392. void
  1393. dio_cact(chan,n)
  1394. CHAN *chan;
  1395. {
  1396.     chan->cact = n;
  1397. }
  1398.  
  1399. void
  1400. dio_close(chan)
  1401. register CHAN *chan;
  1402. {
  1403.     dio_abort(chan);
  1404.     lunlink(&chan->link);
  1405.     if (--chan->base->refs == 0) {
  1406.     FreeMem(chan->base, sizeof(DIO));
  1407.     CloseDevice(&chan->ior);
  1408.     }
  1409.     if (chan->timer.io_Message.mn_ReplyPort)
  1410.     CloseDevice(&chan->timer);
  1411.     DeletePort(chan->CPORT);
  1412.     FreeMem(chan, sizeof(CHAN));
  1413. }
  1414.  
  1415. void
  1416. dio_closegroup(chan)
  1417. register CHAN *chan;
  1418. {
  1419.     register CHAN *nextc;
  1420.  
  1421.     for (chan = chan->base->list; chan; chan = nextc) {
  1422.     chan = (CHAN *)((char *)chan - ((char *)&chan->link - (char *)chan));
  1423.     nextc = (CHAN *)chan->link.next;
  1424.     dio_close(chan);
  1425.     }
  1426. }
  1427.  
  1428.  
  1429. CHAN *
  1430. dio_dup(chan)
  1431. register CHAN *chan;
  1432. {
  1433.     register CHAN *nc;
  1434.  
  1435.     if (chan) {
  1436.     nc = (CHAN *)AllocMem(sizeof(CHAN), MPC);   if (!nc) goto fail2;
  1437.     nc->ior = chan->ior;
  1438.     nc->base = chan->base;
  1439.     nc->CPORT = CreatePort(NULL,0);         if (!nc->CPORT) goto fail1;
  1440.     nc->ior.ior.io_Flags = NULL;
  1441.     nc->cact = chan->cact;
  1442.     nc->ddl = chan->ddl;
  1443.     nc->flagmask = chan->flagmask;
  1444.     ++nc->base->refs;
  1445.     llink(&nc->base->list, &nc->link);
  1446.     return(nc);
  1447. fail1:    FreeMem(nc, sizeof(CHAN));
  1448.     }
  1449. fail2:
  1450.     return(NULL);
  1451. }
  1452.  
  1453. dio_signal(chan)
  1454. CHAN *chan;
  1455. {
  1456.     return(chan->CPORT->mp_SigBit);
  1457. }
  1458.  
  1459. dio_flags(chan,or,and)
  1460. long chan;
  1461. {
  1462.     IOR *ior = (void *)chan;
  1463.  
  1464.     ior->io_Flags = (ior->io_Flags | or) & ~and;
  1465. }
  1466.  
  1467.  
  1468. CHAN *
  1469. dio_ctl_to(chan, com, buf, len, to)
  1470. register CHAN *chan;
  1471. char *buf;
  1472. {
  1473.     register long mask;
  1474.  
  1475.     if (chan->timer.io_Message.mn_ReplyPort == NULL) {
  1476.     chan->timer.io_Message.mn_ReplyPort = chan->CPORT;
  1477.     chan->timer.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  1478.     if (OpenDevice("timer.device", UNIT_VBLANK, &chan->timer, 0)) {
  1479.         puts("Panic: DIO_CTL_TO: No timer.device");
  1480.     }
  1481.     chan->timer.io_Command = TR_ADDREQUEST;
  1482.     }
  1483.     mask = 1 << chan->CPORT->mp_SigBit;
  1484.     dio_ctl(chan, (com>0)?-com:com, buf, len);  /* SendIO the request */
  1485.     chan->timer.io_Actual = to / 1000000;
  1486.     chan->timer.io_Length = to % 1000000;    /* setup timer          */
  1487.     chan->timer.io_Flags = 0;
  1488.     BeginIO(&chan->timer);          /* start timer running  */
  1489.     while (Wait(mask)) {            /* Wait for something   */
  1490.     if (CheckIO(chan))          /* request done         */
  1491.         break;
  1492.     if (CheckIO(&chan->timer)) {    /* timeout?           */
  1493.         dio_abort(chan);
  1494.         break;
  1495.     }
  1496.     }
  1497.     AbortIO(&chan->timer);          /*  kill the timer  */
  1498.     WaitIO(&chan->timer);           /*  remove from rp  */
  1499.     return(chan);                   /*  return ior  */
  1500. }
  1501.  
  1502.  
  1503. CHAN *
  1504. dio_ctl(chan, com, buf, len)
  1505. register CHAN *chan;
  1506. char *buf;
  1507. {
  1508.     if (chan->notclear) {   /* wait previous req to finish */
  1509.     WaitIO(chan);
  1510.     chan->notclear = 0;
  1511.     }
  1512.     if (com) {
  1513.     if (chan->cact)
  1514.         chan->ior.ior.io_Actual = 0;    /* initialize io_Actual to 0*/
  1515.     chan->ior.ior.io_Error = 0;        /* initialize error to 0 */
  1516.     if (!chan->ddl) {
  1517.         chan->ior.ior.io_Data = (APTR)buf;  /* buffer   */
  1518.         chan->ior.ior.io_Length = len;    /* length   */
  1519.     }
  1520.     if (com < 0) {                      /* asyncronous IO  */
  1521.         chan->ior.ior.io_Command = -com;
  1522.         chan->notclear = 1;
  1523.         chan->ior.ior.io_Flags &= chan->flagmask;
  1524.         BeginIO(chan);
  1525.     } else {                /* syncronous IO  */
  1526.         chan->ior.ior.io_Command = com;
  1527.         chan->ior.ior.io_Flags = (chan->ior.ior.io_Flags & chan->flagmask) | IOF_QUICK;
  1528.         BeginIO(chan);
  1529.         if (!(chan->ior.ior.io_Flags & IOF_QUICK))
  1530.         WaitIO(chan);
  1531.     }
  1532.     }
  1533.     return(chan);
  1534. }
  1535.  
  1536.  
  1537. CHAN *
  1538. dio_isdone(chan)
  1539. register CHAN *chan;
  1540. {
  1541.     if (chan->notclear) {       /* if not clear */
  1542.     if (CheckIO(chan)) {    /* if done      */
  1543.         WaitIO(chan);       /* clear        */
  1544.         chan->notclear = 0;
  1545.         return(chan);       /* done         */
  1546.     }
  1547.     return(NULL);           /* notdone      */
  1548.     }
  1549.     return(chan);               /* done         */
  1550. }
  1551.  
  1552.  
  1553. CHAN *
  1554. dio_wait(chan)
  1555. register CHAN *chan;
  1556. {
  1557.     if (chan->notclear) {
  1558.     WaitIO(chan);           /* wait and remove from rp */
  1559.     chan->notclear = 0;
  1560.     }
  1561.     return(chan);
  1562. }
  1563.  
  1564.  
  1565. CHAN *
  1566. dio_abort(chan)
  1567. register CHAN *chan;
  1568. {
  1569.     if (chan->notclear) {
  1570.     AbortIO(chan);          /* Abort it   */
  1571.     WaitIO(chan);           /* wait and remove from rp */
  1572.     chan->notclear = 0;
  1573.     }
  1574.     return(chan);
  1575. }
  1576.  
  1577.  
  1578. \Rogue\Monster\
  1579. else
  1580.   echo "will not over write ./suplib/dio.c"
  1581. fi
  1582. if [ `wc -c ./suplib/dio.c | awk '{printf $1}'` -ne 11170 ]
  1583. then
  1584. echo `wc -c ./suplib/dio.c | awk '{print "Got " $1 ", Expected " 11170}'`
  1585. fi
  1586. if `test ! -s ./suplib/asyncop.c`
  1587. then
  1588. echo "writing ./suplib/asyncop.c"
  1589. cat > ./suplib/asyncop.c << '\Rogue\Monster\'
  1590.  
  1591. /*
  1592.  *  ASYNCOP.C
  1593.  */
  1594.  
  1595. typedef unsigned char    ubyte;
  1596. typedef unsigned short    uword;
  1597. typedef unsigned long    ulong;
  1598. typedef struct Message    MSG;
  1599. typedef struct MsgPort    PORT;
  1600. typedef struct Task    TASK;
  1601. typedef struct Node    NODE;
  1602.  
  1603. #define ASYMSG    struct _ASYMSG
  1604. #define ASYHAN    struct _ASYHAN
  1605.  
  1606. ASYMSG {
  1607.     MSG msg;
  1608.     void (*func)();
  1609.     long arg1;
  1610.     long arg2;
  1611.     long arg3;
  1612. };
  1613.  
  1614. ASYHAN {
  1615.     PORT *rport;    /*    Reply Port    */
  1616.     PORT *port;     /*    Send Port    */
  1617.     long acount;    /*    Messages Sent    */
  1618.     long ccount;    /*    Messages Replied*/
  1619.     long a4,a5;     /*    A4 and A5    */
  1620. };
  1621.  
  1622. extern TASK *CreateTask();
  1623. extern TASK *FindTask();
  1624. extern PORT *CreatePort();
  1625. extern void *AllocMem();
  1626. extern void *GetMsg();
  1627.  
  1628. extern void asyhandler();
  1629. extern void nop();
  1630.  
  1631.  
  1632. ASYHAN *
  1633. NewAsyncOp()
  1634. {
  1635.     register TASK *task;
  1636.     register TASK *mytask = FindTask(NULL);
  1637.     register ASYHAN *as = AllocMem(sizeof(ASYHAN), MEMF_CLEAR|MEMF_PUBLIC);
  1638.     ASYMSG StartupMsg;
  1639.  
  1640.     as->rport = CreatePort(NULL, 0);
  1641.     PutA4A5(&as->a4);
  1642.     task = CreateTask("async.task", mytask->tc_Node.ln_Pri + 1, asyhandler, 4096);
  1643.     task->tc_UserData = (APTR)as;
  1644.  
  1645.     Signal(task, SIGBREAKF_CTRL_F);
  1646.     Wait(1 << as->rport->mp_SigBit);
  1647.  
  1648.     return(as);
  1649. }
  1650.  
  1651.  
  1652. StartAsyncOp(as, func, arg1, arg2, arg3)
  1653. register ASYHAN *as;
  1654. void (*func)();
  1655. {
  1656.     register ASYMSG *am = GetMsg(as->rport);    /*  Free Msg List   */
  1657.  
  1658.     if (!am) {
  1659.     am = AllocMem(sizeof(ASYMSG), MEMF_PUBLIC|MEMF_CLEAR);
  1660.     am->msg.mn_ReplyPort = as->rport;
  1661.     }
  1662.     am->func = func;
  1663.     am->arg1 = arg1;
  1664.     am->arg2 = arg2;
  1665.     am->arg3 = arg3;
  1666.     ++as->acount;
  1667.     PutMsg(as->port, am);
  1668. }
  1669.  
  1670. CheckAsyncOp(as, n)
  1671. register ASYHAN *as;
  1672. unsigned long n;
  1673. {
  1674.     if (n > as->acount)
  1675.     n = as->acount;
  1676.     return(n <= as->ccount);
  1677. }
  1678.  
  1679. /*
  1680.  *  acount = #messages sent
  1681.  *  ccount = #messages replied
  1682.  */
  1683.  
  1684. WaitAsyncOp(as, n)
  1685. register ASYHAN *as;
  1686. unsigned long n;
  1687. {
  1688.     if (n > as->acount)
  1689.     n = as->acount;
  1690.     while (n > as->ccount)
  1691.     Wait(1 << as->rport->mp_SigBit);
  1692.     Forbid();
  1693.     as->ccount -= n;
  1694.     Permit();
  1695.     as->acount -= n;
  1696. }
  1697.  
  1698. CloseAsyncOp(as)
  1699. register ASYHAN *as;
  1700. {
  1701.     ASYMSG EndMsg;
  1702.     ASYMSG *am;
  1703.  
  1704.     WaitAsyncOp(as, -1);                /*  Wait for all operations to complete */
  1705.     while (am = GetMsg(as->rport))      /*  Free any messages   */
  1706.     FreeMem(am, sizeof(ASYMSG));
  1707.     EndMsg.func = NULL;
  1708.     EndMsg.msg.mn_ReplyPort = as->rport;
  1709.     PutMsg(as->port, &EndMsg);
  1710.     WaitPort(as->rport);
  1711.     GetMsg(as->rport);
  1712.     DeletePort(as->rport);
  1713.     FreeMem(as, sizeof(*as));
  1714. }
  1715.  
  1716. static
  1717. void
  1718. asyhandler()
  1719. {
  1720.     register ASYHAN *as;
  1721.     register ASYMSG *am;
  1722.  
  1723.     Wait(SIGBREAKF_CTRL_F);
  1724.     as = (ASYHAN *)FindTask(NULL)->tc_UserData;
  1725.     as->port = CreatePort(NULL, 0);
  1726.     Signal(as->rport->mp_SigTask, 1 << as->rport->mp_SigBit);
  1727.     for (;;) {
  1728.     WaitPort(as->port);
  1729.     am = GetMsg(as->port);
  1730.     if (!am->func)
  1731.         break;
  1732.     CallAMFunc(&as->a4, &am->func);
  1733.     ++as->ccount;
  1734.     ReplyMsg(am);
  1735.     }
  1736.     DeletePort(as->port);
  1737.     as->port = NULL;
  1738.     Forbid();
  1739.     ReplyMsg(am);
  1740. }
  1741.  
  1742. #asm
  1743.         ;
  1744.         ;    load the lw array ptr with a4 & a5
  1745.  
  1746. _PutA4A5:   move.l  4(sp),A0
  1747.         move.l  A4,(A0)+
  1748.         move.l  A5,(A0)+
  1749.         rts
  1750.  
  1751. _CallAMFunc:
  1752.         move.l  4(sp),A0    ; &a4,a5
  1753.         move.l  8(sp),A1    ; &func,arg1,arg2,arg3
  1754.         movem.l D2/D3/A4/A5/A6,-(sp)
  1755.         move.l  (A0)+,A4
  1756.         move.l  (A0)+,A5
  1757.         move.l  12(A1),-(sp)
  1758.         move.l  8(A1),-(sp)
  1759.         move.l  4(A1),-(sp)
  1760.         move.l  (A1),A1
  1761.         jsr     (A1)
  1762.         add.w   #12,sp
  1763.         movem.l (sp)+,D2/D3/A4/A5/A6
  1764.         rts
  1765.  
  1766. #endasm
  1767.  
  1768. \Rogue\Monster\
  1769. else
  1770.   echo "will not over write ./suplib/asyncop.c"
  1771. fi
  1772. if [ `wc -c ./suplib/asyncop.c | awk '{printf $1}'` -ne 3495 ]
  1773. then
  1774. echo `wc -c ./suplib/asyncop.c | awk '{print "Got " $1 ", Expected " 3495}'`
  1775. fi
  1776. if `test ! -s ./suplib/enviroment.c`
  1777. then
  1778. echo "writing ./suplib/enviroment.c"
  1779. cat > ./suplib/enviroment.c << '\Rogue\Monster\'
  1780.  
  1781. /*
  1782.  *  ENVIROMENT.C
  1783.  *
  1784.  *  str = GetDEnv(name)
  1785.  *  bool= SetDEnv(name, str)    (0=failure, 1=success)
  1786.  *
  1787.  *    If the enviroment variable 'name' exists, malloc and return a copy
  1788.  *    of it.    The user program must free() it (or allow the standard C
  1789.  *    exit routine to free() it).
  1790.  */
  1791.  
  1792. extern void *AllocMem();
  1793. extern void *malloc();
  1794.  
  1795. char *
  1796. GetDEnv(name)
  1797. char *name;
  1798. {
  1799.     short nlen = strlen(name) + 5;
  1800.     char *ptr = AllocMem(nlen, MEMF_PUBLIC);
  1801.     char *res = NULL;
  1802.     long fh;
  1803.     long len;
  1804.  
  1805.     if (ptr) {
  1806.     strcpy(ptr, "ENV:");
  1807.     strcat(ptr, name);
  1808.     if (fh = Open(ptr, 1005)) {
  1809.         len = (Seek(fh, 0L, 1), Seek(fh, 0L, 0));
  1810.         if (len >= 0 && (res = malloc(len+1))) {
  1811.         Seek(fh, 0L, -1);
  1812.         if (Read(fh, res, len) != len)
  1813.             len = 0;
  1814.         res[len] = 0;
  1815.         }
  1816.         Close(fh);
  1817.     }
  1818.     FreeMem(ptr, nlen);
  1819.     }
  1820.     return(res);
  1821. }
  1822.  
  1823. SetDEnv(name, str)
  1824. char *name, *str;
  1825. {
  1826.     short nlen = strlen(name) + 5;
  1827.     short slen = strlen(str);
  1828.     short res = 0;
  1829.     char *ptr = AllocMem(nlen, MEMF_PUBLIC);
  1830.     long fh;
  1831.  
  1832.     if (ptr) {
  1833.     strcpy(ptr, "ENV:");
  1834.     strcat(ptr, name);
  1835.     if (fh = Open(ptr, 1006)) {
  1836.         if (Write(fh, str, slen) == slen)
  1837.         res = 1;
  1838.         Close(fh);
  1839.     }
  1840.     FreeMem(ptr, nlen);
  1841.     }
  1842.     return(res);
  1843. }
  1844.  
  1845. \Rogue\Monster\
  1846. else
  1847.   echo "will not over write ./suplib/enviroment.c"
  1848. fi
  1849. if [ `wc -c ./suplib/enviroment.c | awk '{printf $1}'` -ne 1213 ]
  1850. then
  1851. echo `wc -c ./suplib/enviroment.c | awk '{print "Got " $1 ", Expected " 1213}'`
  1852. fi
  1853. if `test ! -s ./suplib/typedefs.h`
  1854. then
  1855. echo "writing ./suplib/typedefs.h"
  1856. cat > ./suplib/typedefs.h << '\Rogue\Monster\'
  1857.  
  1858. /*
  1859.  * TYPEDEFS.H
  1860.  */
  1861.  
  1862. typedef unsigned char    ubyte;
  1863. typedef unsigned short    uword;
  1864. typedef unsigned long    ulong;
  1865.  
  1866. typedef struct MsgPort        PORT;
  1867. typedef struct Message        MSG;
  1868. typedef struct List        LIST;
  1869. typedef struct Node        NODE;
  1870. typedef struct MinList        MLIST;
  1871. typedef struct MinNode        MNODE;
  1872. typedef struct Device        DEV;
  1873. typedef struct Library        LIB;
  1874. typedef struct ExecBase     EXECBASE;
  1875.  
  1876. #define WINSTD    (WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE)
  1877.  
  1878. typedef struct BoolInfo     BOOLINFO;
  1879. typedef struct Border        BORDER;
  1880. typedef struct Gadget        GADGET;
  1881. typedef struct Image        IMAGE;
  1882. typedef struct IntuiMessage    IMESS;
  1883. typedef struct IntuiText    ITEXT;
  1884. typedef struct Menu        MENU;
  1885. typedef struct MenuItem     ITEM;
  1886. typedef struct NewScreen    NS;
  1887. typedef struct NewWindow    NW;
  1888. typedef struct Preferences    PREFS;
  1889. typedef struct PropInfo     PROPINFO;
  1890. typedef struct Remember     REMEMBER;
  1891. typedef struct Requester    REQUESTER;
  1892. typedef struct Screen        SCR;
  1893. typedef struct StringInfo    STRINGINFO;
  1894. typedef struct Window        WIN;
  1895.  
  1896. typedef struct GListEnv     GLISTENV;
  1897. typedef struct GadgetInfo    GADGETINFO;
  1898. typedef struct IBox        IBOX;
  1899. typedef struct IntuitionBase    IBASE;
  1900. typedef struct PenPair        PENPAIR;
  1901. typedef struct Point        POINT;
  1902.  
  1903. typedef struct IOAudio        IOAUD;
  1904.  
  1905. typedef struct BootBlock    BOOTBLOCK;
  1906.  
  1907. typedef struct IOClipReq        IOCLIPREQ;
  1908. typedef struct ClipboardUnitPartial CLIPUNIT;
  1909. typedef struct SatisfyMsg        SATISFYMSG;
  1910.  
  1911. typedef struct ConUnit        CONUNIT;
  1912. typedef struct IOStdReq     IOCON;
  1913.  
  1914. typedef struct InputEvent    IE;
  1915.  
  1916. typedef struct TextAttr     TA;
  1917. typedef struct TextFont     FONT;
  1918. typedef struct Layer        LAYER;
  1919. typedef struct Layer_Info    LAYERINFO;
  1920. typedef struct Region        REGION;
  1921. typedef struct ClipRect     CLIPRECT;
  1922. typedef struct BitMap        BM;
  1923. typedef struct RastPort     RP;
  1924. typedef struct View        VIEW;
  1925. typedef struct ViewPort     VP;
  1926. typedef struct GfxBase        GFXBASE;
  1927.  
  1928. typedef struct Process        PROC;
  1929. typedef struct Task        TASK;
  1930. typedef struct FileInfoBlock    FIB;
  1931. typedef struct FileLock     LOCK;
  1932.  
  1933. typedef struct timeval        TV;
  1934. typedef struct timerequest    IOTIM;
  1935.  
  1936. typedef struct PrinterData    PD;
  1937. typedef struct PrinterExtendedData PED;
  1938.  
  1939.  
  1940. /*
  1941.  *  Intuition
  1942.  */
  1943.  
  1944. extern WIN    *OpenWindow();
  1945. extern SCR    *OpenScreen();
  1946. extern void    *AllocRemember();
  1947. extern void    *ItemAddress();
  1948. extern PREFS    *GetPrefs();
  1949. extern PREFS    *GetDefPrefs();
  1950. extern VIEW    *ViewAddress();
  1951. extern VP    *ViewPortAddress();
  1952.  
  1953. /*
  1954.  *  Graphics
  1955.  */
  1956.  
  1957. extern void    *AllocRaster();
  1958.  
  1959. /*
  1960.  *  Exec / Exec-Support
  1961.  */
  1962.  
  1963. extern void    *GetMsg();
  1964. extern void    *GetHead(), *GetTail(), *GetSucc(), *GetPred();
  1965. extern void    *GetHeadOff(), *GetTailOff(), *GetSuccOff(), *GetPredOff();
  1966.  
  1967. extern void    *AllocMem();
  1968. extern PORT    *FindPort();
  1969. extern TASK    *CreateTask();
  1970. extern PROC    *CreateProc();
  1971. extern void    *FindTask();    /*  task or proc    */
  1972.  
  1973. extern void    *malloc();
  1974.  
  1975.  
  1976.  
  1977.  
  1978. \Rogue\Monster\
  1979. else
  1980.   echo "will not over write ./suplib/typedefs.h"
  1981. fi
  1982. if [ `wc -c ./suplib/typedefs.h | awk '{printf $1}'` -ne 2748 ]
  1983. then
  1984. echo `wc -c ./suplib/typedefs.h | awk '{print "Got " $1 ", Expected " 2748}'`
  1985. fi
  1986. if `test ! -s ./suplib/xmisc.h`
  1987. then
  1988. echo "writing ./suplib/xmisc.h"
  1989. cat > ./suplib/xmisc.h << '\Rogue\Monster\'
  1990.  
  1991. /*
  1992.  * XMISC.H
  1993.  */
  1994.  
  1995. #ifndef    MYLIB_XMISC_H
  1996. #define    MYLIB_XMISC_H
  1997.  
  1998. #define    GRAPHICS_LIB        0x0001L
  1999. #define    INTUITION_LIB        0x0002L
  2000. #define    EXPANSION_LIB        0x0004L
  2001. #define    DISKFONT_LIB        0x0008L
  2002. #define    TRANSLATOR_LIB        0x0010L
  2003. #define    ICON_LIB        0x0020L
  2004. #define    MATH_LIB        0x0040L
  2005. #define    MATHTRANS_LIB        0x0080L
  2006. #define    MATHIEEEDOUBBAS_LIB 0x0100L
  2007. #define    MATHIEEESINGBAS_LIB 0x0200L
  2008. #define    LAYERS_LIB        0x0400L
  2009. #define    CLIST_LIB        0x0800L
  2010. #define    POTGO_LIB        0x1000L
  2011. #define    TIMER_LIB        0x2000L
  2012.  
  2013. struct OLI {
  2014.     char *name;
  2015.     long *var;
  2016. };
  2017.  
  2018. typedef    struct _XLIST {
  2019.     struct _XLIST *next, **prev;
  2020. } XLIST;
  2021.  
  2022. #endif
  2023.  
  2024.  
  2025. \Rogue\Monster\
  2026. else
  2027.   echo "will not over write ./suplib/xmisc.h"
  2028. fi
  2029. if [ `wc -c ./suplib/xmisc.h | awk '{printf $1}'` -ne 644 ]
  2030. then
  2031. echo `wc -c ./suplib/xmisc.h | awk '{print "Got " $1 ", Expected " 644}'`
  2032. fi
  2033. if `test ! -s ./suplib/dio.h`
  2034. then
  2035. echo "writing ./suplib/dio.h"
  2036. cat > ./suplib/dio.h << '\Rogue\Monster\'
  2037.  
  2038. /*
  2039.  * DIO.H
  2040.  *
  2041.  *  (C)Copyright 1987 Matthew Dillon, All Rights Reserved
  2042.  *  Freely distributable.  Donations welcome, I guess.
  2043.  *
  2044.  *    Matthew Dillon
  2045.  *    891 Regal Rd.
  2046.  *    Berkeley, Ca.    94708
  2047.  *
  2048.  */
  2049.  
  2050. #ifndef MYLIB_DIO_H
  2051. #define MYLIB_DIO_H
  2052. #include <exec/types.h>
  2053. #include <exec/io.h>
  2054. #include <exec/memory.h>
  2055. #include <exec/ports.h>
  2056. #include <devices/timer.h>
  2057.  
  2058. typedef struct IORequest IOR;
  2059. typedef struct IOStdReq  STD;
  2060. typedef struct MsgPort     PORT;
  2061.  
  2062. /*
  2063.  *    'to' is in microsections.  The IO request structure
  2064.  *  pointer is optional to dio_open().    If NULL, dio_open()
  2065.  *  initializes it's own IO request (to mostly zero).  You have
  2066.  *  to provide an IO request structure, for instance, if openning
  2067.  *  a console device since the window pointer must be passed to
  2068.  *  OpenDevice().
  2069.  *
  2070.  *    each DFD descriptor has it's own signal.
  2071.  *
  2072.  *    dio_isdone() returns 1 if the channel is clear, 0 otherwise.
  2073.  */
  2074.  
  2075. extern long dio_open();     /* dfd      = dio_open(devname,unit,flags,req)*/
  2076. extern long dio_dup();        /* newdfd = dio_dup(dfd)    */
  2077. extern STD *dio_ctl();        /* req    = dio_ctl(dfd,com,buf,len)        */
  2078. extern STD *dio_ctl_to();    /* req    = dio_ctl_to(dfd,com,buf,len,to)    */
  2079. extern STD *dio_wait();     /* req    = dio_wait(dfd)     */
  2080. extern STD *dio_abort();    /* req    = dio_abort(dfd)    */
  2081. extern STD *dio_isdone();    /* req    = dio_isdone(dfd)   */
  2082. extern int dio_signal();    /* signm= dio_signal(dfd)   */
  2083. extern void dio_close();    /*  dio_close(dfd)        */
  2084. extern void dio_cloesgroup();    /*  dio_closegroup(dfd)     */
  2085. extern void dio_cact();     /*  dio_cact(dfd,bool)        */
  2086.  
  2087.  
  2088.  
  2089. /*
  2090.  * dio_simple() and related macros return the !io_Error field. That
  2091.  * is, 0=ERROR, 1=OK
  2092.  *
  2093.  * dio_actual() returns the io_Actual field.
  2094.  *
  2095.  * NOTE: the io_Actual field may not be set by the device if an
  2096.  * error condition exists.  To make the io_ctl() and io_ctl_to()
  2097.  * call automatically clear the io_Actual field before doing the
  2098.  * io operation, use the DIO_CACT() call.  The reason this isn't
  2099.  * done automatically by default is that some devices require
  2100.  * parameters to be passed in the io_Actual field (like the
  2101.  * timer.device).
  2102.  *
  2103.  *  Remember, Asyncronous IO is done by sending -com instead of com.
  2104.  *
  2105.  *    CALL                Syncronous IO   Asyncronous IO
  2106.  *
  2107.  *  dio_simple(dfd,com)         0=ERROR, 1=OK   undefined
  2108.  *  dio_actual(dfd,com)         io_Actual        undefined
  2109.  *  dio_reset(dfd)            0=ERROR, 1=OK   n/a
  2110.  *  dio_update(dfd)            0=ERROR, 1=OK   n/a
  2111.  *  dio_clear(dfd)            0=ERROR, 1=OK   n/a
  2112.  *  dio_stop(dfd)            0=ERROR, 1=OK   n/a
  2113.  *  dio_start(dfd)            0=ERROR, 1=OK   n/a
  2114.  *  dio_flush(dfd)            0=ERROR, 1=OK   n/a
  2115.  *  dio_getreq(dfd)            returns a ptr to the IO
  2116.  *                    request structure
  2117.  *  NOTE: If you use the following, you probably want to have the
  2118.  *  device library automatically clear the io_Actual field before
  2119.  *  sending the request so you get 0 if an error occurs.  That
  2120.  *  is: dio_cact(dfd,1);
  2121.  *
  2122.  *
  2123.  *  dio_read(dfd,buf,len)        returns actual bytes read
  2124.  *  dio_write(dfd,buf,len)        returns actual bytes written
  2125.  *
  2126.  *    The timeout argument for dio_readto() and dio_writeto()
  2127.  *    is in MICROSECONDS, up to 2^31uS.
  2128.  *
  2129.  *  dio_readto(dfd,buf,len,to)        returns actual bytes read
  2130.  *  dio_writeto(dfd,buf,len,to)     returns actual bytes written
  2131.  *
  2132.  *    The asyncronous dio_reada() and dio_writea() do not
  2133.  *    return anything.
  2134.  *
  2135.  *  dio_reada(dfd,buf,len)        begin asyncronous read
  2136.  *  dio_writea(dfd,buf,len)        begin asyncronous write
  2137.  */
  2138.  
  2139. #define dio_mask(dfd)        (1 << dio_signal(dfd))
  2140.  
  2141. #define dio_simple(dfd,com)    (!dio_ctl(dfd,com,0,0)->io_Error)
  2142. #define dio_actual(dfd,com)    ( dio_ctl(dfd,com,0,0)->io_Actual)
  2143. #define dio_reset(dfd)        dio_simple(dfd,CMD_RESET)
  2144. #define dio_update(dfd)     dio_simple(dfd,CMD_UPDATE)
  2145. #define dio_clear(dfd)        dio_simple(dfd,CMD_CLEAR)
  2146. #define dio_stop(dfd)        dio_simple(dfd,CMD_STOP)
  2147. #define dio_start(dfd)        dio_simple(dfd,CMD_START)
  2148. #define dio_flush(dfd)        dio_simple(dfd,CMD_FLUSH)
  2149. #define dio_getreq(dfd)     dio_ctl(dfd,0,0,0)
  2150.  
  2151. #define dio_read(dfd,buf,len)        (dio_ctl(dfd,CMD_READ,buf,len)->io_Actual)
  2152. #define dio_write(dfd,buf,len)        (dio_ctl(dfd,CMD_WRITE,buf,len)->io_Actual)
  2153. #define dio_readto(dfd,buf,len,to)  (dio_ctl_to(dfd,CMD_READ,buf,len,to)->io_Actual)
  2154. #define dio_writeto(dfd,buf,len,to) (dio_ctl_to(dfd,CMD_WRITE,buf,len,to)->io_Actual)
  2155. #define dio_reada(dfd,buf,len)        ((void)dio_ctl(dfd,-CMD_READ,buf,len))
  2156. #define dio_writea(dfd,buf,len)     ((void)dio_ctl(dfd,-CMD_WRITE,buf,len))
  2157.  
  2158. #endif
  2159.  
  2160.  
  2161. \Rogue\Monster\
  2162. else
  2163.   echo "will not over write ./suplib/dio.h"
  2164. fi
  2165. if [ `wc -c ./suplib/dio.h | awk '{printf $1}'` -ne 4438 ]
  2166. then
  2167. echo `wc -c ./suplib/dio.h | awk '{print "Got " $1 ", Expected " 4438}'`
  2168. fi
  2169. if `test ! -s ./suplib/conwin.c`
  2170. then
  2171. echo "writing ./suplib/conwin.c"
  2172. cat > ./suplib/conwin.c << '\Rogue\Monster\'
  2173.  
  2174. /*
  2175.  *  CONWIN.C
  2176.  *
  2177.  *  Win = GetConWindow()
  2178.  *
  2179.  *  Returns console window associated with the current task or NULL if
  2180.  *  no console task associated.
  2181.  *
  2182.  *  The intuition.library and graphics.library must be openned.
  2183.  */
  2184.  
  2185. #include <exec/types.h>
  2186. #include <exec/memory.h>
  2187. #include <intuition/intuition.h>
  2188. #include <libraries/dos.h>
  2189. #include <libraries/dosextens.h>
  2190.  
  2191. #define BTOC(bptr)    ((long)(bptr) << 2)
  2192. #define CTOB(cptr)    ((long)(cptr) >> 2)
  2193.  
  2194. typedef struct Task          TASK;
  2195. typedef struct Process          PROC;
  2196. typedef struct StandardPacket STDPKT;
  2197. typedef struct MsgPort          MSGPORT;
  2198. typedef struct Window          WIN;
  2199. typedef struct InfoData       INFODATA;
  2200.  
  2201. extern TASK *FindTask();
  2202. extern void *AllocMem();
  2203.  
  2204. /*
  2205.  *  GETCONWINDOW()
  2206.  *
  2207.  *  Return the window used by the console of the current process.  We can
  2208.  *  use our process's message port as the reply port since it is a
  2209.  *  synchronous packet (we wait for the result to come back).  WARNING:
  2210.  *  This routine does not check if the 'console' of the current process
  2211.  *  is really a console device.
  2212.  *
  2213.  *  The DISK_INFO packet is sent to the console device.  Although this
  2214.  *  packet is normally used to retrieve disk information from disk
  2215.  *  devices, the console device recognizes the packet and places a pointer
  2216.  *  to the window in id_VolumeNode of the infodata structure.  A pointer
  2217.  *  to the console unit is also placed in id_InUse of the infodata structure.
  2218.  */
  2219.  
  2220. WIN *
  2221. GetConWindow()
  2222. {
  2223.     PROC    *proc;
  2224.     STDPKT    *packet;
  2225.     INFODATA    *infodata;
  2226.     long    result;
  2227.     WIN     *win;
  2228.  
  2229.     proc   = (PROC *)FindTask(NULL);
  2230.     if (!proc->pr_ConsoleTask)
  2231.     return(NULL);
  2232.     /*
  2233.      *    NOTE: Since DOS requires the packet and infodata structures to
  2234.      *    be longword aligned, we cannot declare them globally or on the
  2235.      *    stack (word aligned).  AllocMem() always returns longword
  2236.      *    aligned pointers.
  2237.      */
  2238.  
  2239.     packet   = (STDPKT   *)AllocMem(sizeof(STDPKT)  , MEMF_CLEAR|MEMF_PUBLIC);
  2240.     infodata = (INFODATA *)AllocMem(sizeof(INFODATA), MEMF_CLEAR|MEMF_PUBLIC);
  2241.  
  2242.     packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  2243.     packet->sp_Pkt.dp_Link = &packet->sp_Msg;
  2244.     packet->sp_Pkt.dp_Port = &proc->pr_MsgPort;
  2245.     packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  2246.     packet->sp_Pkt.dp_Arg1 = CTOB(infodata);
  2247.     PutMsg(proc->pr_ConsoleTask, packet);
  2248.     WaitPort(&proc->pr_MsgPort);
  2249.     GetMsg(&proc->pr_MsgPort);
  2250.  
  2251.     result = packet->sp_Pkt.dp_Res1;
  2252.     win = (WIN *)infodata->id_VolumeNode;
  2253.     /* note: id_InUse holds a pointer to the console unit also */
  2254.     FreeMem(packet  , sizeof(STDPKT));
  2255.     FreeMem(infodata, sizeof(INFODATA));
  2256.     if (!result)
  2257.     return(NULL);
  2258.     return(win);
  2259. }
  2260.  
  2261.  
  2262. \Rogue\Monster\
  2263. else
  2264.   echo "will not over write ./suplib/conwin.c"
  2265. fi
  2266. if [ `wc -c ./suplib/conwin.c | awk '{printf $1}'` -ne 2672 ]
  2267. then
  2268. echo `wc -c ./suplib/conwin.c | awk '{print "Got " $1 ", Expected " 2672}'`
  2269. fi
  2270. echo "Finished archive 1 of 2"
  2271. # if you want to concatenate archives, remove anything after this line
  2272. exit
  2273. -- 
  2274. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  2275. Have five nice days.
  2276.